define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',

                    table: 'member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                searchFormVisible: false,
                commonSearch: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'nick_name', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'sex', title: __('sex'),formatter: Table.api.formatter.status, searchList: {1: '男', 2: '女',3 :'不详'}},
                        {field: 'phone', title: __('phone')},
                        {field: 'card_code', title: __('card_code')},
                        {field: 'birth', title: __('birth'), addclass: 'datetimepicker'},
                        {field: 'created_at', title: __('created_at'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'channel', title: __('channel'),formatter: Table.api.formatter.status, searchList: {1: '堂食小程序', 2: '外卖小程序'}},

                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [
                            //     {
                            //     name: 'send_coupons',
                            //     text: __('send_coupons'),
                            //     icon: 'fa fa-list',
                            //     classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                            //     url: "user/user/send_coupons"
                            // },
                                {
                                name: 'up_integral',
                                text: __('up_integral'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: "user/user/up_integral"
                            }],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});